/**
 * Copyright Yao Xuanyu @ CST04, Tsinghua University
 */
package cn.edu.tsinghua.sthuapp;

import org.json.*;

import android.util.Log;

/**
 * Data structure for each event/activity.<br>
 * Can be reused in client.
 * 
 * @author Yao Xuanyu
 * @version 5.0
 */
public class Event {
	
	private int id = 0;
	private int classification = 0;
	private String title = new String();
	private String date = new String();
	private String time = new String();
	private String location = new String();
	private String ticketTime = new String();
	private String ticketLocation = new String();
	private String releaseTime = new String();
	private String content = new String();
	private String image = new String();
	private String organizer = new String();

	public String getOrganizer() {
		return organizer;
	}

	public void setOrganizer(String organizer) {
		this.organizer = organizer;
	}


	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public int getClassification() {
		return classification;
	}

	public void setClassification(int classification) {
		this.classification = classification;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getDate() {
		return date;
	}

	public void setDate(String date) {
		this.date = date;
	}

	public String getTime() {
		return time;
	}

	public void setTime(String time) {
		this.time = time;
	}

	public String getLocation() {
		return location;
	}

	public void setLocation(String location) {
		this.location = location;
	}

	public String getTicketTime() {
		return ticketTime;
	}

	public void setTicketTime(String ticketTime) {
		this.ticketTime = ticketTime;
	}

	public String getTicketLocation() {
		return ticketLocation;
	}

	public void setTicketLocation(String ticketLocation) {
		this.ticketLocation = ticketLocation;
	}

	public String getReleaseTime() {
		return releaseTime;
	}

	public void setReleaseTime(String releaseTime) {
		this.releaseTime = releaseTime;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String getImage() {
		return image;
	}

	public void setImage(String image) {
		this.image = image;
	}
	
	/**
	 * Parse JSON string into Event.
	 * 
	 * @see org.json.JSONObject
	 * @see java.text.DateFormat
	 * @param JSON Event data in JSON format.
	 */
	public void parseEvent(String JSON) {
		try {
			JSON = JSON.replaceAll("&#x2F;", "/");
			JSONObject json = new JSONObject(JSON);
			this.id = json.getInt("id");
			this.classification = json.getInt("classification");
			this.title = JsonGetString(json, "title");
			this.date = JsonGetString(json, "date");
			this.time = JsonGetString(json, "time");
			this.location = JsonGetString(json, "location");
			this.ticketTime = JsonGetString(json, "ticketTime");
			this.ticketLocation = JsonGetString(json, "ticketLocation");
			this.releaseTime = JsonGetString(json, "releaseTime");
			this.content = JsonGetString(json, "content");
			this.image = JsonGetString(json, "image");
			this.organizer = JsonGetString(json, "organizer");
			// EVENT DATA FORMAT
			// TODO for code reuse.
			//this.date = DateFormat.getDateInstance(DateFormat.FULL).format(this.date);
			//this.ticketTime = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.SHORT).format(this.ticketTime);
			//this.releaseTime = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.SHORT).format(this.releaseTime);
		} catch (JSONException e) {
			// TODO Auto-generated catch block
		}
	}
	
	private String JsonGetString(JSONObject json, String key) {
		String str = "";
		try {
			str = json.getString(key);
		} catch (JSONException e) {
			
		}
		return str;
	}
}
